$(function() {
	/*YDUI.dialog.loading.open("正在加载");*/
	var arr = []
	$.post("selectPrizeByCode", {
		"code": "00"
	}, function(data) {
		/*alert(JSON.stringify(data))*/
		data=data.data
		if(data.length > 0) {
			var html2 = '<tr><td>编号</td><td>奖品</td></tr>';
			var html = '<th>网点名称</th>'
			for(var i in data) {
				html2 += '<tr><td>' + data[i].奖品代码 + '</td><td>' + data[i].奖品名称 + '</td></tr>';
				html += '<th class="thorder">' + data[i].奖品代码 + '</th>'
				arr.push(data[i].奖品代码)
			}
			$("#tab_top").html(html)
			$("#list").html(html2)
			$.post("selectCountByDotPrize", {}, function(data) {
//				alert(JSON.stringify(data))
				data=data.data
				if(data.length > 0) {
					var html = ''
					for(var i in data) {
						html += '<tr><td>' + data[i].name + '</td>';
						html += abb(data[i]) + '</tr>'
					}
					$("#tab").html(html)
					YDUI.dialog.loading.close();
				}
			})
		}
	})

	$.post("selectCountByDot", function(data) {
		/*alert(JSON.stringify(data))*/
		if(data.length > 0) {
			for(var i in data) {
				wdname.push(data[i].name)
				wd.push(data[i].人数)
			}
			$("#wdtj").css("height", data.length * 30 + 200)
			wdtj()
		} else {
			var html = '<div style="height:150px;line-height:150px;text-align:center;font-size:16px;background:white;">暂无数据</div>'
			$("#wdtj").html(html)
		}
	})

})
var wdname = []
var wd = []
var wdname2 = []
var wd2 = []

function wdtj() {
	$('#wdtj').highcharts({
		chart: {
			type: 'bar'
		},
		title: {
			text: ''
		},
		xAxis: {
			categories: wdname,
			title: {
				text: null
			}
		},
		yAxis: {
			min: 0,
			title: {
				text: '参与人数(人)',
				align: 'high'
			},
			labels: {
				overflow: 'justify'
			}
		},
		tooltip: {
			valueSuffix: ' 人'
		},
		plotOptions: {
			bar: {
				dataLabels: {
					enabled: true,
					allowOverlap: true
				}
			}
		},

		credits: {
			enabled: false
		},
		series: [{
			name: '参与人数',
			data: wd
		}]

	});
}

function lqtj() {
	$('#lqtj').highcharts({
		chart: {
			type: 'bar'
		},
		title: {
			text: ''
		},
		xAxis: {
			categories: wdname2,
			title: {
				text: null
			}
		},
		yAxis: {
			min: 0,
			title: {
				text: '发券数量',
				align: 'high'
			},
			labels: {
				overflow: 'justify'
			}
		},
		tooltip: {
			valueSuffix: ' 人'
		},
		plotOptions: {
			bar: {
				dataLabels: {
					enabled: true,
					allowOverlap: true
				}
			}
		},

		credits: {
			enabled: false
		},
		series: [{
			name: '发券数量',
			data: wd2
		}]

	});
}

function abb(a, arr) {
	var html = ''
	$(".thorder").each(function() {
		var n = $(this).text();
		for(var i in a) {
			if(i == n) {
				html += '<td>' + a[i] + '</td>';
				break;
			}
		}
	})

	return html
}
